import {defineComponent, h, inject, computed, provide, PropType, watch, ref} from "vue";
import {YvLocale} from '../../YvLocale'

export default defineComponent({
    name: 'YvConfigProvider',
    props: {
        locale: Object as PropType<YvLocale | null>,
    },
    emits: ['changeLocale'],
    setup(props, {emit}) {
        const locale = ref(props.locale)

        watch(() => props.locale, (value) => {
            locale.value = value
        })

        provide('YvConfigProvider', {
            locale: locale,
            changeLanguage: (value) => {
                emit('changeLocale', value)
            }
        })
    },
    render() {
        return h(this.$slots.default)
    }
})